/* 网站根目录
*/
var baseDir = '';
/* Window functions
*/
var winFunc = {
  toString: function() {
    return location;
  },
  /* 获取锚点
  */
  get_anchor: function() {
    var href = location.href;
    var anchor = href.indexOf('#') == -1 ?
      false :
      href.substring(href.indexOf('#')+1);
    return anchor;
  },
  /* 设置锚点
  */
  set_anchor: function($var) {
    //alert($var);
    var href = location.href;
    if(href.indexOf('#') == -1) {
      location = href + "#" + $var;
    } else {
      location = href.substring(0, href.indexOf('#')) + "#" + $var;
    }
  },
  reload: function() {
    location.reload();
    //location = location;
  },
  go: function(sUrl, sTarget) {
    if(typeof sTarget=='undefined') {
      location = sUrl;
    } else {
      sTarget.location = sUrl;
    }
    if($.browser.msie) event.srcElement.href = '#';
    return;
  },
  top: function() {
    window.scrollTo(0, 0);
  },
  bottom: function() {
    window.scrollTo(0, 9999);
  },
  open: function(sUrl) {
    window.open(sUrl);
  },
  /* 获取文件扩展名
   * dellker.com 2007-10-31
  */
  getExt: function(sFile) {
    if(!sFile) return;
    else{
      var a = sFile.split(".");
      if(a.length>0) return a[a.length-1].toLowerCase();
      else return false;
    }
  },
  debug: function(o) {
    var name='debugcontainer';
    var msg='';
    for(a in o)msg+=a+": "+o[a]+"<br />";
    if(document.getElementById(name)) {
      var obj=document.getElementById(name);
    }else{
      var obj=document.createElement('div');
      obj.id=name;
      obj.style.backgroundColor="#FFFFFF";
      obj.style.border="solid 2px #F00";
      obj.style.margin="1em";
      obj.style.padding=".5em";
      obj.style.fontSize="1.2em";
      obj.style.lineHeight="160%";
      document.body.appendChild(obj);
    }
    obj.innerHTML = msg;
  }
}/* end winFunc*/

/* 重写图片大小 */
function drawImage(img, w, h) {
	var image=new Image();
  image.src = img.src;
  var w = w||540;
  var h = h||400;
  var _rate = w/h;
  var rate = image.width/image.height;
  if(image.width>w){
    if(image.height>h && _rate>rate) {
      img.height = h;
      img.width = rate*h;
    } else {
      img.width = w;
      img.height = w/rate;
    }
  } else if(image.height>h) {
    img.height = h;
    img.width = rate*h;
  }
  var lf = parseInt((660-img.width)/2) + 'px';
  $('.hoverContainer').css({'height':img.height, 'width':img.width, 'left':lf});
  $('.next').add('.previous').css('height', img.height);
}
/**
 * 获取文件扩展名
 * dellker.com 2007-10-31
 * wkkes.com 2008-9-3 17:44
*/
function getExtension(sFile) {
  if(! sFile) {
    return '';
  } else {
    var a = sFile.split('.');
    if(a.length>0) {
      return a[a.length-1].toLowerCase();
    } else {
      return '';
    }
  }
}
function getPos(el, sProp) {
	var iPos = 0;
	while (el!=null) {
    iPos+=el["offset" + sProp];
    el = el.offsetParent;
	}
	return iPos;
}

/**
 * Garden
 */
function ShowDiv(ObjID) {
	for(var i=1;i<3;i++) {
		if(document.getElementById("title_"+i)) {
			document.getElementById("title_"+i).className=(ObjID==i)?"cur":"";
			document.getElementById("ul_"+i).style.display=(ObjID==i)?"block":"none";
		} else return;
	}
}
function autoTab($headClassName) {
  $("."+$headClassName).each(function(i,n) {
    var __currentTabIndex = 0;
    $("a", n).each(function(j,o) {
      $(o).click(function() {
        $("a", n).slice(__currentTabIndex, __currentTabIndex+1).removeClass("cur");
        $(this).addClass("cur");
        //alert($(n).parent().parent().find(".text ul").size());
        $(n).parent().parent().find(".text ul").slice(__currentTabIndex, __currentTabIndex+1).hide();
        $(n).parent().parent().find(".text ul").slice(j, j+1).show();
        __currentTabIndex = j;
      });
    });
  });
}

/**
 * 计数器功能
 */
function log(type, id) {
  if(!type) return;
  if( id>0 ) {
    var par = {
      rnd   : Math.random(),
      type  : type,
      id    : id
    }
    $.get(baseDir + "/index.php/log", par);
  }
}

/**
 * 博客访问计数器功能
 */
function logs(type, id, aid) {
  if(!type) return;
  if( id>0 ) {
    var par = {
      rnd   : Math.random(),
      type  : type,
      id    : id,
	  aid   : aid
    }
    $.get(baseDir + "/index.php/log", par);
  }
}

/**
 * ---复制/拷贝文本内容(兼容IE和ff)
 */
function copyText(obj)
{
    if( obj.type !="hidden" )
    {
        obj.focus();
    }
    obj.select(); 
    copyToClipboard(obj.value);
    alert("拷贝成功！");
}
function copyToClipboard(txt) {  
    if(window.clipboardData)  
    {  
        window.clipboardData.clearData();  
        window.clipboardData.setData("Text", txt);  
    }  
    else if(navigator.userAgent.indexOf("Opera") != -1)  
    {  
        window.location = txt;  
    }  
    else if (window.netscape)  
    {  
        try {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }  
        catch (e)  
        {  
            alert("您的firefox安全限制限制您进行剪贴板操作，\n请打开'about:config'将'signed.applets.codebase_principal_support'设置为'true'之后重试 \n或者进行手工复制");
        }  
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);  
        if (!clip)  
            return;  
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);  
        if (!trans)  
            return;  
        trans.addDataFlavor('text/unicode');  
        var str = new Object();  
        var len = new Object();  
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);  
        var copytext = txt;  
        str.data = copytext;  
        trans.setTransferData("text/unicode",str,copytext.length*2);  
        var clipid = Components.interfaces.nsIClipboard;  
        if (!clip)  
            return false;  
        clip.setData(trans,null,clipid.kGlobalClipboard);  
    }  
    return true;  
}

function redirect_mem() {
  var item = parseInt( $('input[name=item]').val() );
  if(isNaN(item) || item<100000) {
    alert("请输入一个有效的纪念馆馆号");
  } else {
    window.open("http://www.eeloves.com/" + item);
  }
}

function selCnl(e) {
  var url = __baseUrl + '/channel-cp/setting/identity';
  var identity = $(e).val();
  $.get(url, {identity: identity, rnd: Math.random()}, function(s) {
    winFunc.reload();
  });
}